package com.xca.is.repository;

import com.xca.is.entity.TopNews;
import com.xca.is.service.TopNewsService;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.schedulers.Schedulers;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/*String key = "6cbcdb4250c543fc38a812cce2026a31";
String url = "http://v.juhe.cn/" ;*/
public class TopNewsRepository {
    private static final String URL = "http://v.juhe.cn/" ;
    private static final String KEY = "6cbcdb4250c543fc38a812cce2026a31" ;
    private TopNewsService service ;

    public TopNewsRepository(){
                Retrofit retrofit = new Retrofit.Builder()
                        .baseUrl(URL)
                        .addCallAdapterFactory(RxJava3CallAdapterFactory.create())
                        .addConverterFactory(GsonConverterFactory.create())
                        .build() ;
                service = retrofit.create(TopNewsService.class);
    }

    public Observable<TopNews> getData(String type){
        return service.getData(type,KEY)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io());
    }
}
